package com.gitee.wsl.mathematics.geometry.d3.polygon.ext

import com.gitee.wsl.ext.number.approx
import com.gitee.wsl.mathematics.base.Tagged
import com.gitee.wsl.mathematics.geometry.d3.polygon.Polyhedron
import com.gitee.wsl.mathematics.geometry.d3.polygon.transform.transformedPolyhedron


enum class Scale(override val tag: String) : Tagged {
    Inradius("i"),
    Midradius("m"),
    Circumradius("c");
}

val Scales: List<Scale> by lazy { Scale.entries }

private object ScaledKey

fun Polyhedron.scaled(factor: Double): Polyhedron = transformedPolyhedron(ScaledKey, factor) {
    for (v in vs) vertex( v * factor , v.kind)
    for (f in fs) face(f)
}

fun Polyhedron.scaled(scale: Scale?): Polyhedron {
    if (scale == null) return this
    val current = scaleDenominator(scale)
    if (current approx 1.0) return this // fast path, don't occupy cache slot
    return scaled(1 / current)
}